package com.jic.member.controller.manage;

import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.member.common.util.BeanUtil;
import com.jic.member.entity.MememberUser;
import com.jic.member.entity.power.MeintegralLog;
import com.jic.member.request.MememberUserRequest;
import com.jic.member.request.power.MeintegralLogRequest;
import com.jic.member.response.DistributionMemberResponse;
import com.jic.member.response.MememberUserResponse;
import com.jic.member.response.power.MeintegralLogResponse;
import com.jic.member.service.MememberUserService;
import com.jic.member.service.power.MeintegralLogService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

@ApiOperation(value = "查询分销员列表controller")
@RestController
@RequestMapping("/distribution")
@Slf4j
public class DistributionMemberController {

    @Autowired
    MememberUserService memberUserService;
    /*
     * 分页查询
     * */
    @ApiOperation(value = "获取分销员列表")
    @ResponseBody
    @RequestMapping("/queryDistributionMemberPage")
    public RestResult<PageResult<DistributionMemberResponse>> queryDistributionMemberPage(@RequestBody MememberUserRequest form) {
        log.info("开始进入会员积分流水列表=========》,{}", form.toString());
        Page page = new Page();
        page.setLimit(form.getLimit());
        page.setStart(form.getStart());
        MememberUser memberRequest = BeanUtil.copy(form, MememberUser.class);
        memberRequest.setAllocationStatus(1);
        PageResult<MememberUser> result = memberUserService.queryDistributionMemberPage(memberRequest, page);
        List<DistributionMemberResponse> memberResponseList = result.getRows().stream().map(temp -> {
            DistributionMemberResponse memberResponse = BeanUtil.copy(temp, DistributionMemberResponse.class);
            return memberResponse;
        }).filter(item -> item != null).collect(Collectors.toList());
        PageResult<DistributionMemberResponse> pageResult = new PageResult<>();
        pageResult.setRows(memberResponseList);
        pageResult.setTotal(result.getTotal());
        return RestResult.success(pageResult);
    }

    /*
     * 分页查询
     * */
    @ApiOperation(value = "获取分销员代理列表")
    @ResponseBody
    @RequestMapping("/queryDistributionProxyPage")
    public RestResult<PageResult<DistributionMemberResponse>> queryDistributionProxyPage(@RequestBody MememberUserRequest form) {
        log.info("开始进入会员积分流水列表=========》,{}", form.toString());
        Page page = new Page();
        page.setLimit(form.getLimit());
        page.setStart(form.getStart());
        MememberUser memberRequest = BeanUtil.copy(form, MememberUser.class);
        memberRequest.setAllocationStatus(2);
        PageResult<MememberUser> result = memberUserService.queryDistributionMemberPage(memberRequest, page);
        List<DistributionMemberResponse> memberResponseList = result.getRows().stream().map(temp -> {
            DistributionMemberResponse memberResponse = BeanUtil.copy(temp, DistributionMemberResponse.class);
            return memberResponse;
        }).filter(item -> item != null).collect(Collectors.toList());
        PageResult<DistributionMemberResponse> pageResult = new PageResult<>();
        pageResult.setRows(memberResponseList);
        pageResult.setTotal(result.getTotal());
        return RestResult.success(pageResult);
    }

}
